//
//  WJCDeployModel.m
//  WJCLibrary
//
//  Created by wjc on 2022/2/8.
//

#import "WJCDeployModel.h"
#import "WJCDefine.h"
@interface WJCDeployModel ()
@property (strong, nonatomic) NSMutableDictionary * dic;
@end
@implementation WJCDeployModel
+ (instancetype)sharedInfoDeploy {
    static WJCDeployModel *_sharedSingleton = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //不能再使用alloc方法
        //因为已经重写了allocWithZone方法，所以这里要调用父类的分配空间的方法
        _sharedSingleton = [[WJCDeployModel alloc] init];
    });
    return _sharedSingleton;
}
+(id)getDeployWithStr:(NSString*)deployKey{
    WJCDeployModel *deploy = [WJCDeployModel sharedInfoDeploy];
#ifdef DEBUG // 开发阶段-DEBUG阶段:
    NSCAssert(deploy.dic[@"homeAPI"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find homeAPI appschema\nWJCDeployModel 模型homeAPI必须要有\n❌❌❌❌❌❌❌-------------------/");
    NSCAssert(deploy.dic[@"appName"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find appName appschema\nWJCDeployModel 模型appName必须要有\n❌❌❌❌❌❌❌-------------------/");
    NSCAssert(deploy.dic[@"appschema"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find appschema appschema\nWJCDeployModel 模型appschema必须要有\n❌❌❌❌❌❌❌-------------------/");
#endif
    if (!deploy.dic) {
        deploy.dic = [NSMutableDictionary new];
    }
    return deploy.dic[deployKey];
}
+ (id)getDeployWithDeployKey:(deployModelKey)key{

    WJCDeployModel *deploy = [WJCDeployModel sharedInfoDeploy];
#ifdef DEBUG // 开发阶段-DEBUG阶段:
    NSCAssert(deploy.dic[@"homeAPI"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find homeAPI appschema\nWJCDeployModel 模型homeAPI必须要有\n❌❌❌❌❌❌❌-------------------/");
    NSCAssert(deploy.dic[@"appName"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find appName appschema\nWJCDeployModel 模型appName必须要有\n❌❌❌❌❌❌❌-------------------/");
    NSCAssert(deploy.dic[@"appschema"], @"\n/-------------------❌❌❌❌❌❌❌\nWJCDeployModel model can't find appschema appschema\nWJCDeployModel 模型appschema必须要有\n❌❌❌❌❌❌❌-------------------/");
#endif
    switch (key) {
        case WJCDeployAPIHeadUrl:
            return deploy.dic[@"homeAPI"];
            break;
        case WJCDeployAPPName:
            return deploy.dic[@"appName"];
            break;
        case WJCDeployAPPSchema:
            return deploy.dic[@"appschema"];
            break;
        case WJCDeployImageHeadUrl:
            return deploy.dic[@"imageAPIUrl"];
            break;
        case WJCDeployAddImage:
            return deploy.dic[@"addImg"];
            break;
        case WJCDeployEnv:
            return deploy.dic[@"env"];
            break;
        case WJCDeployHeadImage:
            if ([deploy.dic[@"headPlaceImg"] isKindOfClass:[NSString class]]) {
                return [UIImage imageNamed:deploy.dic[@"headPlaceImg"]];
            }
            return deploy.dic[@"headPlaceImg"];
            break;
        case WJCDeployUploadImageUrl:
        {
            if (!deploy.dic[@"uploadAPIUrl"]) {
                return deploy.dic[@"homeAPI"];
            }
            return deploy.dic[@"uploadAPIUrl"];
        }
        case WJCDeployUploadImageUrls:
        {
            if (!deploy.dic[@"uploadAPIUrls"]) {
                return deploy.dic[@"homeAPI"];
            }
            else if (deploy.dic[@"uploadAPIUrls"]) {
                return deploy.dic[@"uploadAPIUrls"];
            }
            return deploy.dic[@"uploadAPIUrl"];
        }
        default:
            return nil;
            break;
    }
}
+(void)setDeployWithDic:(NSDictionary *)dic{
    WJCDeployModel *deploy = [WJCDeployModel sharedInfoDeploy];
    if (!deploy.dic) {
        deploy.dic = [NSMutableDictionary new];
    }
        for (NSString *key in dic) {
            [deploy.dic setValue:dic[key] forKey:key];
        }
}
+ (void)setDeployWithDeployKey:(deployModelKey)key andValue:(nonnull NSString *)value{
    WJCDeployModel *deploy = [WJCDeployModel sharedInfoDeploy];
    switch (key) {
        case WJCDeployAPIHeadUrl:
            [deploy.dic setValue:value forKey:@"homeAPI"];
            if (!deploy.dic[@"uploadAPIUrl"]) {
                [deploy.dic setValue:value forKey:@"uploadAPIUrl"];
            }
            break;
        case WJCDeployAPPName:
            [deploy.dic setValue:value forKey:@"appName"];
            break;
        case WJCDeployAPPSchema:
            [deploy.dic setValue:value forKey:@"appschema"];
            break;
        case WJCDeployImageHeadUrl:
            [deploy.dic setValue:value forKey:@"imageAPIUrl"];
            break;
        case WJCDeployAddImage:
            [deploy.dic setValue:value forKey:@"addImg"];
            break;
        case WJCDeployHeadImage:
            [deploy.dic setValue:value forKey:@"headPlaceImg"];
            break;
        case WJCDeployEnv:
            [deploy.dic setValue:value forKey:@"env"];
            break;
        case WJCDeployUploadImageUrl:
            
            [deploy.dic setValue:value forKey:@"uploadAPIUrl"];
            break;
        case WJCDeployUploadImageUrls:
            
            [deploy.dic setValue:value forKey:@"uploadAPIUrls"];
            break;
        default:
            break;
    }
}
@end
